﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Documents;
using System.Windows.Media;

namespace AnesSystem
{
    public class CustomDocumentPaginator : DocumentPaginator
    {
        private int _pageCount=0;
        private Size printerSize;
        private Size singePageSize;
        private List<FrameworkElement> _elments;
        private FrameworkElement _elment;
        private ScaleTransform _scaleTransform;

        public CustomDocumentPaginator(List<FrameworkElement> printElements,Size printerSize,Size singePageSize, int printCount,ScaleTransform scaleTransform)
        {
            _elments = printElements;
            this.printerSize = printerSize;
            _pageCount = printCount;
            this.singePageSize = singePageSize;
            _scaleTransform = scaleTransform;
        }
        public CustomDocumentPaginator(FrameworkElement printElement, Size printerSize, ScaleTransform scaleTransform)
        {
            _elment = printElement;
            this.printerSize = printerSize;
            this._scaleTransform = scaleTransform;
        }

        public override bool IsPageCountValid
        {
            get
            {
                return true;
            }
        }

        public override int PageCount
        {
            get
            {
                return _pageCount;
            }
        }

        public override Size PageSize
        {
            get
            {
                return printerSize;
            }

            set
            {
                printerSize = value;
            }
        }

        public override IDocumentPaginatorSource Source
        {
            get
            {
                return null;
            }
        }

        public override DocumentPage GetPage(int pageNumber)
        {
            FrameworkElement visual = _elments[pageNumber];
            visual.Measure(singePageSize);
            visual.Arrange(new System.Windows.Rect(singePageSize));
            visual.RenderTransform = _scaleTransform;
            visual.UpdateLayout();
            DocumentPage p = new DocumentPage(visual);
            return p;
        }
    }
}
